import './App.css';
import React from "react";
import ReactQuill,{Quill} from 'react-quill';
import hljs from 'highlight.js'
import 'react-quill/dist/quill.snow.css'

import  ImageResize  from 'quill-image-resize-module';
import Counter from "./quillcounter";
import htmlEditButton from "quill-html-edit-button";

Quill.register("modules/htmlEditButton", htmlEditButton);
Quill.register('modules/imageResize', ImageResize);
Quill.register('modules/counter', Counter);

function App() {
  return (
    <div className="App">
        <MyComponent/>
    </div>
  );
}


class MyComponent extends React.Component {

    constructor(props) {
        super(props);
        this.state = {value:""}
        hljs.configure({   // optionally configure hljs
            languages: ['javascript', 'ruby', 'python','go','golang']
        });
    }

    setValue = (newValue) => {
        this.setState({
            value: newValue
        })
    }

    toolbarOptions = [
        [{ 'size': ['small', false, 'large', 'huge'] },  // custom dropdown
        { 'header': [1, 2, 3, 4, 5, 6, false] }],

        ['bold', 'italic', 'underline', 'strike',        // toggled buttons
        'blockquote', 'code-block'],

        [{ 'header': 1 }, { 'header': 2 }],               // custom button values
        [{ 'list': 'ordered'}, { 'list': 'bullet' },
            { 'direction': 'rtl' }],                         // text direction
        [{ 'script': 'sub'}, { 'script': 'super' }],      // superscript/subscript

        [{ 'color': [] }, { 'background': [] },          // dropdown with defaults from theme
        { 'font': [] },
        { 'align': [] }],
        ['link', 'image', 'video'],
        ['clean']                                         // remove formatting button
    ];
    modules = {
        syntax: {
            highlight: text => hljs.highlightAuto(text).value,
        },
        imageResize: {
            modules: [ 'Resize', 'DisplaySize', 'Toolbar' ]
        },
        toolbar:this.toolbarOptions,
        counter:true,
        htmlEditButton: {
            debug: true, // logging, default:false
            msg: "Edit the content in HTML format", //Custom message to display in the editor, default: Edit HTML here, when you click "OK" the quill editor's contents will be replaced
            okText: "Ok", // Text to display in the OK button, default: Ok,
            cancelText: "Cancel", // Text to display in the cancel button, default: Cancel
            buttonHTML: "&lt;&gt;", // Text to display in the toolbar button, default: <>
            buttonTitle: "Show HTML source", // Text to display as the tooltip for the toolbar button, default: Show HTML source
            syntax: false
        }
    }

    render() {
        return (
            <ReactQuill className="quill" modules={this.modules} theme="snow" value={this.state.value} onChange={this.setValue}/>
        );
    }
}

export default App;
